// sgu367
// 题解：
// 拓扑排序水题。
//
// ml:run = $bin < input
#include <iostream>
#include <vector>
#include <queue>

int const maxn = 1007;
int tim[maxn];
int indegree[maxn];
int n, t, m;

struct data { int tim, id; };
bool operator<(data const& a, data const& b)
{
    return a.tim > b.tim;
}

std::vector<std::vector<int>> graph;

void add_edge(int u, int v)
{
    graph[u].push_back(v);
    indegree[v]++;
}

std::priority_queue<data> pq;

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin >> n >> t;
    graph.resize(n + 1);
    for (int i = 1; i <= n; i++) std::cin >> tim[i];
    std::cin >> m;
    for (int i = 0, x, y; i < m; i++) {
        std::cin >> x >> y;
        add_edge(x, y);
    }
    for (int i = 1; i <= n; i++)
        if (indegree[i] == 0)
            pq.push({tim[i], i});

    long long tot = 0, ans = 0, sum = 0;
    std::vector<int> print;
    while (!pq.empty()) {
        auto now = pq.top(); pq.pop();
        if (sum + now.tim > t) break;
        print.push_back(now.id);

        sum += now.tim; ans += sum; tot++;

        for (auto v : graph[now.id]) {
            indegree[v]--;
            if (indegree[v] == 0) pq.push({tim[v], v});
        }
    }
    std::cout << tot << " " << ans << "\n";
    for (auto i : print) std::cout << i << " ";
    std::cout << "\n";
}

